#!/bin/sh
#********************************************************************************
# Copyright (c) 2022 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache License 2.0 which is available at
# http://www.apache.org/licenses/LICENSE-2.0
#
# SPDX-License-Identifier: Apache-2.0
#*******************************************************************************/


# exit if vcan is up
CAN=$1
[ -z "$CAN" ] && CAN="vcan0"

# NOTE: needs `apt-get install net-tools iproute2 `
ifconfig "$CAN" 2>/dev/null | grep -q UP && exit 0

sudo modprobe vcan
sudo sudo ip link add dev "$CAN" type vcan
sudo sudo ip link set up "$CAN"

ifconfig "$CAN"
